﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ADL;
using CDIO.Models;

namespace CDIO.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/

        public UserModel userModel = null;

        public ActionResult User_Search(string username)
        {
            ViewBag.Message = username;

            ADL_user ad_us = new ADL_user();
            _user us = new _user();
            List<_user> listuse = ad_us.search(null, "*");
            if(listuse!= null)
            {
                userModel = new UserModel
                {
                    account = "" + listuse.Count,
                    UserModel_user = listuse
                };
            }
            return View(userModel);
        }

        public ActionResult User_Add(string username)
        {
            ViewBag.Message = username;
            return View();
        }

        public ActionResult User_Detail(string username, string _user_id)
        {
            ViewBag.Message = username;

            ADL_user ad_us = new ADL_user();
            _user us = new _user();
             us._user_id = _user_id;
             List<_user> listuse = ad_us.search(us, "_user_id");
            if (listuse != null)
            {
                userModel = new UserModel
                {
                    _user_id = listuse[0]._user_id,
                    _user_name = listuse[0]._user_name,
                    _user_psw = listuse[0]._user_psw,
                    _user_phone = listuse[0]._user_phone,
                    _user_credit = listuse[0]._user_credit,
                    _user_level = listuse[0]._user_level
                };
            }

            return View(userModel);
        }

    }
}
